# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=pdsh
pkgver=2.34
pkgrel=0
pkgdesc="A high performance, parallel remote shell utility"
url="https://github.com/chaos/pdsh"
arch="all"
license="GPL-2.0"
depends="perl"
makedepends="autoconf automake libtool readline-dev ncurses-dev"
subpackages="$pkgname-doc $pkgname-rcmd-ssh:_rcmd_ssh"
source="https://github.com/chaos/$pkgname/archive/$pkgname-$pkgver.tar.gz
	without-rresvport.patch
	fix-test-t6036.patch"
builddir="$srcdir/$pkgname-$pkgname-$pkgver"

prepare() {
	default_prepare

	cd "$builddir"
	sed -i "s|m4_esyscmd(\[git describe .*\])|[$pkgver]|" configure.ac
	./bootstrap
}

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-static \
		--without-rsh \
		--with-ssh \
		--with-readline
	make
}

check() {
	cd "$builddir"
	make check
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
}

_rcmd_ssh() {
	pkgdesc="Pdsh module for ssh rcmd functionality"
	depends="$pkgname openssh-client"
	install_if="$pkgname=$pkgver-r$pkgrel openssh-client"

	mkdir -p "$subpkgdir"/usr/lib/$pkgname
	mv "$pkgdir"/usr/lib/$pkgname/sshcmd.* "$subpkgdir"/usr/lib/$pkgname/
}

sha512sums="2d4e090d97f6bad97ee1dbdf2ee29e4d9603edfd5c92a6935131ef7f7bbff797cceb8ad3a72e3d5995d3d5302eac985d129f4968e3fa6744785a3df2d0fda33c  pdsh-2.34.tar.gz
97d9cde907cdfe51cb805dcf772011578cc1485d67ad177e24a4f81283aac2535a400a9d71cc79f4c08f4ae8e5886635203b1c92c910ae915a591eb616b7347a  without-rresvport.patch
8ddfb37a4e7c9550f79e8bf0d24795203f23452541382f8d744adfe40889964fa966655795f2d4d594ee21af3f14c9d2fe93ad98a0620403d5c42aaab1f55949  fix-test-t6036.patch"
